package com.ujson.base.common.utils;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class JsonUtil {

    public static final GsonBuilder gsonBuilder;
    static {
        gsonBuilder = new GsonBuilder();
    }

    public static String pojoToString(Object obj) {
        return gsonBuilder.create().toJson(obj);
    }

    // 不适用fastjson
    /*
    public static <T> T stringToPojo(String json, Class<T> clazz) {
        return JSON.parseObject(json, clazz);
    }*/
    public static <T> T stringToPojo(String json, Class<T> clazz) {
        return gsonBuilder.create().fromJson(json, clazz);
    }
}
